package com.demo.thread.demo_thread_create_way;

/**
 * 1. 继承Thread类,然后重写run方法.（由于Java单继承的特性，这种方式用的比较少）
 * @author peter
 * @date 2022/2/27 19:52
 */
public class Demo1 extends Thread {

    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getId() + ":" + i);
        }
    }

    /**
     * 单继承实现线程，用得比较少（继承受限）
     * @param args
     */
    public static void main(String[] args) throws InterruptedException {
        printThreadInfo();
        Demo1 thread1 = new Demo1();
        Demo1 thread2 = new Demo1();
        Demo1 thread3 = new Demo1();
        thread1.start();
        thread2.start();
        thread3.start();
    }

    private static void printThreadInfo() {
        System.out.println("当前线程ID" + Thread.currentThread().getId());
        System.out.println("当前线程名称" + Thread.currentThread().getName());
        System.out.println("当前线程状态" + Thread.currentThread().getState());
        System.out.println("当前线程优先级" + Thread.currentThread().getPriority());
    }
}
